import { ActionTypes, AssetImages, HttpAPI } from '../constants'
import { AxiosUtil } from '../utils'
import base from './base'
const homeList = 'home'
const getVideoById = 'works/select'
const getUserVideoList = 'works/select/user'
const getPetVideoList = 'works/select/pet'
const changeVideoInfo = 'works/update'
const addVideo = 'works/add'
const deleteVideo = 'wroks/delete'
const relateVideo = 'wroks/addrelate'
const delRelate = 'works/delrelate'
export default {
    getVideoList: function * (payload) {
        const { response, error } = yield AxiosUtil.get(homeList);
        console.log('getVideoList', response, error);
        yield base.after(response, error, ActionTypes.API_GET_VIDEO_LIST_SUCCESS)
    },
    fetchVideoById: function * (payload) {
        const { data, callBack = null } = payload;
        const { response, error } = yield AxiosUtil.get(getVideoById, data);
        yield base.after(response, error, ActionTypes.API_GET_VIDEO_INFO_BY_ID_SUCCESS)
        callBack && callBack(response, error)
    },
    fetchUserVideoList: function * (payload) {
        const { data, callBack = null } = payload;
        const { response, error } = yield AxiosUtil.get(getUserVideoList, data);
        yield base.after(response, error, ActionTypes.API_GET_USER_VIDEO_LIST_BY_USER_SUCCESS)
        callBack && callBack(response, error)
    },
    fetchPetVideoList: function * (payload) {
        const { data, callBack = null, loadType } = payload;
        const { response, error } = yield AxiosUtil.get(getPetVideoList, data)
        if (loadType === 0) {
            yield base.after(response, error, ActionTypes.API_GET_PET_VIDEO_BY_PET_ID_SUCCESS)
        } else {
            // yield base.after()
        }
        
    },
    fetchChangeVideoInfo: function * (payload) {
        const { data, callBack = null } = payload;
        const { response, error } = yield AxiosUtil.get(changeVideoInfo, data)
        yield base.after(response, error, ActionTypes.API_CHANGE_VIDEO_INFO_SUCCESS)
        callBack && callBack(response, error)
    },
    fetchAddVideo: function * (payload) {
        const { data, callBack = null } = payload;
        const { response, error } = yield AxiosUtil.get(addVideo, data)
        yield base.after(response, error, ActionTypes.API_ADD_VIDEO_SUCCESS)
    },
    fetchDeleteVideo: function * (payload) {
        const { data, callBack = null } = payload;
        const { response, error } = yield AxiosUtil.get(deleteVideo, data)
        yield base.after(response, error, ActionTypes.API_DELETE_VIDEO_SUCCESS)
        callBack && callBack(response, error)
    },
    fetchRelateVideo: function * (payload) {
        const { data, callBack = null } = payload;
        const { response, error } = yield AxiosUtil.get(relateVideo, data)
        yield base.after(response, error, ActionTypes.API_RELATE_USER_WITH_USER_SUCCESS)
        callBack && callBack(response, error)
    },
    fetchRemoveRelate: function * (payload) {
        const { data, callBack = null } = payload;
        const { response, error } = yield AxiosUtil.get(delRelate, data)
        yield base.after(response, error, ActionTypes.API_REMOVE_RELATE_USER_WITH_USER_SUCCESS)
        callBack && callBack(response, error)
    },
}